const { program, Command, Option } = require('commander');
// const program = new Command();
program.version('0.0.1');

program
// .option('-d, --debug', 'output extra debugging')
// .option('-s, --small', 'small pizza size')
// .option('-p, --pizza-type <type>', 'flavour of pizza')
.option('--no-sauce', 'remove sauce');

// 构建 Option 对象
// help 不可见 -s 命令
program.addOption(new Option('-s, --secret').hideHelp());
// 设置默认值
program.addOption(new Option('-t, --timeout <delay>').default(60, 'one minute'));
// 规定可选的就 3 个值
program.addOption(new Option('-d, --drink <size>').choices(['small', 'medium', 'large']))
//package.json 的版本自增1
program.option('-p, --patch <v>', 'version add by one', versionAdd);
//这个值可以通过 .opts() 获取
function versionAdd(v){
    console.log(`versionAdd: ${v}`);
    return v;
}

// 通过 command 添加子命令
program.command('close <saurce> [destination]').description('close a repository into a newly created directory').action((saurce, destination)=>{
    //这里一般就是根据值做一些操作
    console.log('clone command called');
    console.log(saurce);
    console.log(destination);
});

let argv = process.argv;
console.log('argv:');
console.log(argv);
//parse 会处理参数，没使用的选项会放在 program.args 数组中
program.parse(process.argv);

//获取各个选项的值组成的对象：{ debug: true, small: true }
let options = program.opts();
console.log(options);
console.log(process.args);